package com.example.demo.common;

import com.example.demo.model.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:  session工具类
 * User: yyx
 * Date: 2023-11-07
 * Time: 11:52
 */
public class SessionUtils {
    //获取当前登录的对象
    public static Userinfo getUser(HttpServletRequest request){
        HttpSession session = request.getSession(false);//如果没有session则不可以重新创建
        if(session==null || session.getAttribute(Appvariable.SESSION_USERINFO_ID)==null) {
            return null;
        }
        //此处需要强转
        return (Userinfo)session.getAttribute(Appvariable.SESSION_USERINFO_ID);

    }
}
